package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.modle.CollectManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.utils.BaseUtil;
import com.sx.zongzhi.view.ICheckMessageView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 * 验证信息的pest
 */

public class CheckMessagePest {

    private ICheckMessageView checkMessageView;

    public CheckMessagePest(ICheckMessageView checkMessageView) {
        this.checkMessageView=checkMessageView;
    }

    /**
     *  验证户籍人口
     * @param path 地址
     * @param idCardNo 身份证号
     * @param accountNumber 户号
     * @param orgId 组织id
     * @param relation 与户主关系
     */
    public void checkHouseHold(String path,String idCardNo,String accountNumber,String orgId,String relation){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        if (!BaseUtil.isEmpty(idCardNo)){
            map.put("population.idCardNo",idCardNo);
        }
        map.put("population.accountNumber",accountNumber);
        map.put("population.organization.id",orgId);
        map.put("population.relationShipWithHead.id",relation);
        new CollectManager().checkHouseHold(path,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                checkMessageView.checkSuccess(response.getData(),response.getErrmsg());
            }
            @Override
            public void onFailures(String message) {
                checkMessageView.showError(message);
            }
        });
    }

    /**
     * 验证 流动人口
     * @param idCardNo 身份证号
     */
    public void checkPopMove(String idCardNo){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("population.idCardNo",idCardNo);
        new CollectManager().checkPopMove(map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                checkMessageView.checkSuccess(response.getData(),response.getErrmsg());
            }
            @Override
            public void onFailures(String message) {
                checkMessageView.showError(message);
            }
        });
    }

    /**
     * 验证 境外人口
     * @param certificateNo  证件号码
     * @param certificateType 证件类型
     * @param orgId 组织id
     * @param id 境外人员id(新增时不提交,更新时提交当前更新的境外人员id)
     */
    public void checkOverseas(String certificateNo,String certificateType,String orgId,String id){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("overseaPersonnel.certificateNo",certificateNo);
        map.put("overseaPersonnel.certificateType.id",certificateType);
        map.put("overseaPersonnel.organization.id",orgId);
        map.put("overseaPersonnel.id",id);
        new CollectManager().checkOverseas(map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                checkMessageView.checkSuccess(response.getData(),response.getErrmsg());
            }
            @Override
            public void onFailures(String message) {
                checkMessageView.showError(message);
            }
        });
    }

}
